<template>
    <div class="dashboard-box">
        <panel v-for="item in panels" v-bind:key="item.name" v-bind:config="item" />
    </div>

</template>

<script>
    import panel from './panel'
    import tag from './tag'
    export default {
        name: 'dashboard',
        components: { panel,tag },
        data: function () {
            return {
                panels: [
                    {
                        name: '待处理',
                        tasks: [
                            {
                                id: 11,
                                title: '添加人物列表渲染功能',
                                owner: 'Rico',
                                dueDate: '2019-09-05 17:00',
                                level: '重要',
                                tag: 'todo',
                                disc: '差200无尽'
                            },
                            {
                                id: 12,
                                title: '绿叉巨九狂徒三星龙女',
                                owner: 'Rico',
                                dueDate: '2019-09-05 17:00',
                                level: '重要',
                                tag: 'todo',
                                disc: '再给我个龙女吧！！！'
                            }
                        ]
                    }, {
                        name: '处理中',
                        tasks: [
                            {
                                id: 21,
                                title: '添加任务创建功能',
                                owner: 'Aeee',
                                dueDate: '2019-09-05 19:00',
                                level: '重要',
                                tag: 'inprogress',
                                disc: '六贵族差天使'
                            }
                        ]
                    }, {
                        name: '已合并',
                        tasks: [
                            {
                                id: 31,
                                title: '我也不知道噶么么哒',
                                owner: 'Yeyeyey',
                                dueDate: '2019-08-03 11:00',
                                level: '重要',
                                tag: 'merged',
                                disc: '六剑士没德莱文'
                            }
                        ]
                    }, {
                        name: '已完成',
                        tasks: [
                            {
                                id: 41,
                                title: '六约德尔三法两龙',
                                owner: 'Cqqqqq',
                                dueDate: '2019-09-03 11:00',
                                level: '重要',
                                tag: 'done',
                                disc: '三星双大天使一羊刀小法'
                            }, {
                                id: 42,
                                title: '添加人物列表渲染功能',
                                owner: 'Rico',
                                dueDate: '2019-09-05 17:00',
                                level: '重要',
                                tag: 'done',
                                disc: '差200无尽'
                            }
                        ]
                    }
                ]
            }
        },
        mounted: function () {
            this.handleAddTask();
        },
        methods: {
            handleAddTask: function () {
                var that = this;
                this.$root.eventHub.$on('addTask', function (taskData) {
                    console.log(taskData);
                    console.log(that.panels)
                    for (var i = 0; i < that.panels.length; i++) {
                        if (that.panels[i].name === taskData.type) {
                            that.panels[i].tasks.push(taskData.data);
                            console.log(taskData.data)
                            break;
                        }
                    }
                });
            }
        }
    }
</script>

<style scoped>
    .dashboard-box {
        display: flex;
    }
</style>